package com.study.daily.algozuo.y2021.m10.day1026;

/**
 * @descriptions: DoubleEnd
 * @author: Tom
 * @date: 2021/10/26 下午 10:06
 * @version: 1.0
 */
public class Code01_DoubleEndQueueImplementByNode {
    public DoubleEnd head;
    public DoubleEnd tail;

    public static void main(String[] args) {

    }

    public DoubleEnd addFromHead(DoubleEnd node) {
        if (head == null) {
            head = node;
            tail = node;
        } else {
            head.pre = node;
            node.next = head;
            head = node;
        }
        return head;
    }

    public DoubleEnd addFromTail(DoubleEnd node) {
        if (tail == null) {
            head = node;
            tail = node;
        } else {
            node.pre = tail;
            tail.next = head;
            tail = node;
        }
        return head;
    }
    public void removeFromHead(){
        if(head==null){
            return;
        } else if(head == tail){
            head = null;
            tail = null;
        } else {
            DoubleEnd next = head.next;
            head.next = null;
            next.pre = null;
            head = next;
        }
    }

}

class DoubleEnd {
    public DoubleEnd pre;
    public DoubleEnd next;
    public int value;

    DoubleEnd(int value) {
        this.value = value;
    }
}
